package iCalImport;

import java.io.File;

import javax.swing.JFileChooser;
import javax.swing.JOptionPane;

/**
 * Dialog zum durchsuchen des Systems nach einer Datei. übergebener String s
 * entspricht dem Fensternamen.
 */
public class FileDialog {
	public static File getFiles(String s) {
		JFileChooser chooser = new JFileChooser();
		chooser.setDialogTitle(s);
		chooser.setCurrentDirectory(new File(System.getProperties()
				.getProperty("user.home")));
		chooser.setMultiSelectionEnabled(false);
		chooser.setFileFilter(new javax.swing.filechooser.FileFilter() {
			@Override
			public boolean accept(File f) {
				return f.getName().toLowerCase().endsWith(".ics")
						|| f.isDirectory();
			}

			public @Override
			String getDescription() {

				return "iCal Files (.ics)";
			}
		});

		int result = chooser.showOpenDialog(null);
		if (result == JFileChooser.CANCEL_OPTION) {
			return null;
		}

		try {
			File files = chooser.getSelectedFile(); // get the file
			return files;
		} catch (Exception ex) {
			JOptionPane.showMessageDialog(null,
					"Warning! Could not load the file(s)!", "Warning!",
					JOptionPane.WARNING_MESSAGE);
			return null;
		}
	}
}
